
package com.sixfoot.adminsys.frames.scale;

import com.sixfoot.domain.scale.Scale;

import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;
import java.util.List;


public class ScaleTableModel extends AbstractTableModel {

    public static final int user_column = 0;
    public static final int resource_column = 1;
    public static final int difficulty_column = 2;
    public static final int starttime_column = 3;
    public static final int stoptime_column = 4;
    public static final int pulsation_column = 5;
    public static final int hrv_column = 6;
    public static final int artifact_column = 7;
    public static final int ibi_column = 8;
    public static final int ppg_column = 9;
    public static final int ep_column = 10;
    public static final int remark_column = 11;
    public static final int timedomain_column = 12;
    public static final int frequencydomain_column = 13;
    public static final int evaluation_column = 14;
    public static final int COLUMN_COUNT = 15;

    private final List<Scale> scales = new ArrayList<Scale>();

    public void add(List<Scale> newScales) {
        int first = scales.size();
        int last = first + newScales.size() - 1;
        scales.addAll(newScales);
        fireTableRowsInserted(first, last);
    }

    public void add(Scale scale) {
        int index = scales.size();
        scales.add(scale);
        fireTableRowsInserted(index, index);
    }

    public int getRowCount() {
        return scales.size();
    }

    public int getColumnCount() {
        return COLUMN_COUNT;
    }

    @Override
    public Class getColumnClass(int column) {
        if (getValueAt(0, column) == null) {
            return "".getClass();
        }
        return getValueAt(0, column).getClass();
    }

    public Scale getScale(int row) {
        return scales.get(row);
    }

    public Object getValueAt(int row, int column) {
        Scale scale = scales.get(row);
        switch (column) {
            case user_column:
                return scale.getUser().getRealName();
            case resource_column:
                return scale.getResource().getName();
            case difficulty_column:
                return scale.getDifficulty();
            case starttime_column:
                return scale.getStartTime();
            case stoptime_column:
                return scale.getStopTime();
            case pulsation_column:
                return scale.getPpg();
            case hrv_column:
                return scale.getHrv();
            case artifact_column:
                return scale.getArtifact();
            case ibi_column:
                return scale.getIbi();
            case ppg_column:
                return scale.getPpg();
            case ep_column:
                return scale.getEp();
            case remark_column:
                return scale.getRemark();
            case timedomain_column:
                return scale.getTimeDomain();
            case frequencydomain_column:
                return scale.getFrequencyDomain();
            case evaluation_column:
                return scale.getEvaluation();

        }
        return null;
    }
}